<template>
  <el-dialog title="账单详情" :visible.sync="dialogVisible" :close-on-click-modal="false" width="850px">
    <div class="">
      <el-descriptions :labelStyle="{
            width:'100px'

          }" :title="formData.createTime" labelClassName="label-txt" border :column='3'>
        <el-descriptions-item label="收支类型">
          <span v-if="formData.type==1">收入</span>
          <span v-if="formData.type==2">支出</span>
        </el-descriptions-item>
        <el-descriptions-item label="账单类型" :span="2">{{ formData.bookType }}</el-descriptions-item>
        <el-descriptions-item label="对方名称">{{ formData.duifangmingcheng }}</el-descriptions-item>
        <el-descriptions-item label="对方账户" :span="2">{{formData.duifangzhanghu  }}</el-descriptions-item>
        <el-descriptions-item label="本方名称">{{formData.benfangmingcheng  }}</el-descriptions-item>
        <el-descriptions-item label="本方账户" :span="3">{{formData.benfangzhanghu  }}</el-descriptions-item>
        <el-descriptions-item label="金额" :span="3">
          <span style="color: red;">¥</span>
          <span style="color: red;font-size: 18px;">{{formData.jine  }}</span>
        </el-descriptions-item>
        <template v-if="billTypeConfig">
          <el-descriptions-item :span="i==billTypeConfig.length-1?3:1" v-for="(item,i) in billTypeConfig" :key="item.id" :label="item.name">{{formData[item.key]  }}</el-descriptions-item>
        </template>

        <el-descriptions-item label="明细" :span="3">{{formData.mingxi  }}</el-descriptions-item>
        <el-descriptions-item label="备注" :span="3">{{formData.beizhu  }}</el-descriptions-item>
        <el-descriptions-item label="图片" :span="3">
          <div v-if="imgList&&imgList.length">
            <el-image style="width:80px;height:80px; margin-right:10px;margin-bottom:10px" :preview-src-list="imgList" preview v-for="(img,i) in imgList" :key="i" :src="img"></el-image>

          </div>
        </el-descriptions-item>
        <el-descriptions-item label="创建人">{{formData.createName  }}</el-descriptions-item>
        <el-descriptions-item label="经办人">{{formData.jingbanren  }}</el-descriptions-item>
        <el-descriptions-item label="复核人">{{formData.fuheren  }}</el-descriptions-item>
      </el-descriptions>
    </div>
  </el-dialog>
</template>

<script>
import jizhangbenApi from "@/api/financeCenter/jizhangben.js";
export default {
  name: "",
  props: ["billTypeList"],
  data() {
    return {
      dialogVisible: false,
      loading: false,
      formData: "",
      imgList: [],
      billTypeConfig: null, //自定义字段配置
    };
  },
  methods: {
    // 打开弹窗
    open(id) {
      this.dialogVisible = true;
      this.imgList = [];
      this.billTypeConfig = null;
      this.getDetail(id);
    },
    getDetail(id) {
      jizhangbenApi.tallyBookInfoById(id).then((res) => {
        this.formData = { ...res.data };
        if (this.formData.img) {
          const arr = JSON.parse(this.formData.img);
          if (arr && arr.length) {
            arr.forEach((r) => {
              this.imgList.push(r.url);
            });
          }
        }
        this.getFields();
      });
    },
    // // 获取账单类型列表
    async getTypeList() {
      const res = await jizhangbenApi.getTypeList();
      if (res.rows && res.rows.length) {
        this.setFieldsConfig(res.rows);
      }
    },
    // 查询账单类型的字段配置
    async getFields() {
      if (this.billTypeList && this.billTypeList.length) {
        this.setFieldsConfig(this.billTypeList);
      } else {
        this.getTypeList()
      }
    },
    // 匹配到当前的字段配置
    setFieldsConfig(list) {
      const showArr = [];
      const temp = list.filter((r) => {
        return r.bookType == this.formData.bookType;
      });
      if (temp && temp.length) {
        let arr = JSON.parse(temp[0].fields);

        if (arr && arr.length) {
          arr.forEach((r) => {
            if (r.isShow) {
              showArr.push({ ...r });
            }
          });
          this.billTypeConfig = showArr;
        }
      }
    },

    close() {
      this.dialogVisible = false;
    },
  },
};
</script>
<style scoped lang="css">
.center {
  text-align: center;
}
</style>
